<?php
extract(extractGet(), EXTR_PREFIX_ALL, 'g');
if ( ! isset($g_project_id) )
{
	jsonErrorDie("Wrong parameters for card_id, user_id or direction.");
}

//inits
$project = R::load('project', $g_project_id);
if ( $project->id == 0 ) jsonErrorDie("Project does not exists");
$project_days = getDaysDiff(date("Y-m-d H:i:s"), $project->created_date);
$columns = getTopLevelColumns($project->board_id);
$backlog = current($columns);
$graph = [];


for ($i = 1; $i <= $project_days; $i ++)
{
	//first line init
	if ( $i == 1 )
		foreach ($columns as $col)
			$graph[ $i - 1 ][ $col->name ] = 0;

	//all logs for current day
	$logs = getLogsMovedAtDay($i - 1, $project->id);

	//apply filter if any
	if ( isset($cards) && ! empty($cards) )
		$logs = array_filter($logs, function ($var) use ($cards)
		{
			return isInBeans($var->cardId, $cards);
		});

	foreach ($columns as $col)
	{
		//get logs for this column
		$log_for_col = array_filter($logs, function ($var) use ($col)
		{
			return R::load('column', $var->currentColumnId)->name == $col->name;
		});

		$graph[ $i ][ $col->name ] = $graph[ $i - 1 ][ $col->name ] + count($log_for_col);
	}
}
?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="width:100%; height:400px;"></div>
<script>
	$(function () {
		$('#container').highcharts({
			title: {
				text: 'Kanbaneros',
				x: -20 //center
			},
			subtitle: {
				text: 'Komulativni Diagram',
				x: -20
			},
			xAxis: {
				categories: [1, 2, 3]
			},
			yAxis: {
				title: {
					text: 'Stevilo kartic v stolpcu'
				},
				plotLines: [
					{
						value: 0,
						width: 1,
						color: '#808080'
					}
				]
			},
			legend: {
				layout: 'vertical',
				align: 'right',
				verticalAlign: 'middle',
				borderWidth: 0
			},
			plotOptions: {
				series: {
					//fillColor: null
				}
			},
			chart: {
				type: 'area'
			},
			series:
			<?php
			$series = [];
			foreach ($columns as $col){
				$data['name'] = $col->name;
				$days = [];
				for($i = 1; $i<$project_days; $i++) {
					$days[] = $graph[$i][$col->name];
				}
				$data['data'] = $days;
				$series[] = $data;
			}
			print json_encode($series);
			?>

		});
	});

</script>
Dan 1: <?php echo date("d.m.Y", strtotime($project->created_date)) ?>

